// https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/
// Created by ade on 2022/10/26.
//
#include <iostream>
#include <string>

class Solution {
public:
    string removeDuplicates(string s) {
        vector<char> st = {s[0]};
        for (int i = 1; i < s.size(); i++) {
            if (!st.empty() && st.back() == s[i]) {
                st.pop_back();
            } else {
                st.push_back(s[i]);
            }
        }
        string res = "";
        for (int i = 0; i < st.size(); i++) {
            res += st[i];
        }
        return res;
    }
};

int main() {
    Solution so;
    string s = "abbaca";
    cout << so.removeDuplicates(s);
    return 0;
}
